package com.guanzi.server.controller;


import com.guanzi.server.entity.Order;
import com.guanzi.server.entity.dto.OrderGenerateDTO;
import com.guanzi.server.entity.vo.StoreVO;
import com.guanzi.server.entity.vo.UserVO;
import com.guanzi.server.query.OrderListQuery;
import com.guanzi.server.service.IOrderService;
import com.guanzi.server.util.Pager;
import com.guanzi.server.util.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author guanzi
 * @since 2021-06-04
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    /**
     * 菜品下单
     * @param orderGenerateDTO
     */
    @PostMapping("/generateOrder")
    public RespBean generateOrder(OrderGenerateDTO orderGenerateDTO) {
        orderService.generateOrder(orderGenerateDTO);
        return RespBean.success("菜品下单成功！");
    }


    /**
     * 订单列表展示（含分页）
     * @param orderListQuery
     * @return
     */
    @PostMapping("/list")
    public RespBean getOrderList( OrderListQuery orderListQuery ) {
        Pager<Order> pager = orderService.getOrderList(orderListQuery);
        return RespBean.success("订单查询成功！", pager);
    }

    /**
     * 获取订单中已有的用户信息
     * @return
     */
    @PostMapping("/getUser")
    public RespBean getUser() {
        List<UserVO> user = orderService.getUser();
        return RespBean.success("获取用户信息成功！", user);
    }

    /**
     * 获取订单中已有的商家信息
     * @return
     */
    @PostMapping("/getStore")
    public RespBean getStore() {
        List<StoreVO> store = orderService.getStore();
        return RespBean.success("获取用户信息成功！", store);
    }
}
